"""
async和await

Python为了将语义变得更加明确，就引入了async和await关键词定义原生的协程。
"""

import types
from collections import Awaitable


async def downloader(url):
    return "Tesla"


@types.coroutine
def downloader_ex(url):
    yield "Apple"


async def download_url(url):
    # do something
    # 可以将await理解为yield from
    html = await downloader(url)
    return html


def use_async_await():
    coro = download_url("https://www.google.com")
    # 需要使用send的方式调用
    coro.send(None)


if __name__ == '__main__':
    use_async_await()
